package com.cadre.web.controller.officer;

import com.cadre.common.utils.R;
import com.cadre.common.utils.annotation.B04ForUpdate;
import com.cadre.common.utils.annotation.SysLog;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.common.utils.oldutil.ValidatorUtils;
import com.cadre.system.domain.officer.B04;
import com.cadre.system.service.B04Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Api(value = "单位职务--b04", tags = {"单位职务接口--b04"})
@RequestMapping({"/unit/b04"})
@RestController
/* loaded from: B04Controller.class */
public class B04Controller {
    @Autowired
    private B04Service b04Service;

    @GetMapping({"/list"})
    @ApiOperation("获取单位职务情况--b04")
    public R list(@RequestParam("unitId") String unitId) {
        return R.ok().put("data", (Object) this.b04Service.selectList(unitId));
    }

    @GetMapping({"/info/{flowid}"})
    @ApiOperation("获取一条职务信息--b04")
    public R info(@PathVariable("flowid") String flowid) {
        return R.ok().put("data", (Object) ((B04) this.b04Service.getBaseMapper().selectById(flowid)));
    }

    @PostMapping({"/save"})
    @SysLog(value = "新增单位职数信息", target = "B01", set = "B04", type = 0)
    @ApiOperation("添加单位职务--b04")
    @B04ForUpdate("insert")
    public R save(@RequestBody Map<String, Object> map) {
        B04 b04 = new B04();
        b04.setFlowid(GenerateUUID.getUUID());
        Map map2 = (Map) map.get("b04");
        if (map2.get("b4101") != null) {
            b04.setB0401(map2.get("b4101").toString());
        }
        if (map2.get("b4102") != null) {
            b04.setB0402(map2.get("b4102").toString());
        }
        if (map2.get("b4103") != null) {
            b04.setB0403(Short.valueOf(Short.parseShort(map2.get("b4103").toString())));
        }
        if (map2.get("b4104") != null) {
            b04.setB0404(map2.get("b4104").toString());
        }
        if (map2.get("b4105") != null) {
            b04.setB0405(map2.get("b4105").toString());
        }
        if (map.get("unitid") != null) {
            b04.setUnitid(map.get("unitid").toString());
        }
        this.b04Service.getBaseMapper().insert(b04);
        return R.ok();
    }

    @PostMapping({"/update"})
    @SysLog(value = "修改单位职数信息", target = "B01", set = "B04", type = 1)
    @ApiOperation("修改职务信息--b04")
    @B04ForUpdate("update")
    public R update(@RequestBody Map<String, Object> map) {
        Map map2 = (Map) map.get("b04");
        B04 b04 = (B04) this.b04Service.getBaseMapper().selectById(map2.get("flowid").toString());
        if (map2.get("b4101") != null) {
            b04.setB0401(map2.get("b4101").toString());
        }
        if (map2.get("b4102") != null) {
            b04.setB0402(map2.get("b4102").toString());
        }
        if (map2.get("b4103") != null) {
            b04.setB0403(Short.valueOf(Short.parseShort(map2.get("b4103").toString())));
        }
        if (map2.get("b4104") != null) {
            b04.setB0404(map2.get("b4104").toString());
        }
        if (map2.get("b4105") != null) {
            b04.setB0405(map2.get("b4105").toString());
        }
        if (map.get("unitid") != null) {
            b04.setUnitid(map.get("unitid").toString());
        }
        ValidatorUtils.validateEntity(b04, new Class[0]);
        this.b04Service.getBaseMapper().updateById(b04);
        return R.ok();
    }

    @PostMapping({"/delete"})
    @SysLog(value = "删除单位职数信息", target = "B01", set = "B04", type = DateUtil.SUB_MONTH)
    @ApiOperation("职务删除--b04")
    @B04ForUpdate("delete")
    public R delete(@RequestBody Map<String, Object> map) {
        this.b04Service.removeBatchByIds(Arrays.asList(map.get("thisIds").toString().split(",")));
        return R.ok();
    }

    @PostMapping({"/updateOrder"})
    @ApiOperation("家庭成员批量排序")
    public R updateOrder(@RequestBody List<B04> entityList) {
        if (entityList.size() > 0) {
            for (int i = 0; i < entityList.size(); i++) {
                this.b04Service.updateByPrimaryKeySelective(entityList.get(i));
            }
        }
        return R.ok("操作成功!");
    }
}
